home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Hot Mix 17
/
Hot Mix 17.iso
/
HM17_SGI
/
research
/
lib
/
norm.pro
< prev
next >
Wrap
Text File
|
1997-07-08
|
3KB
|
85 lines
;$Id: norm.pro,v 1.9 1997/01/15 03:11:50 ali Exp $
;
; Copyright (c) 1994-1997, Research Systems, Inc. All rights reserved.
; Unauthorized reproduction prohibited.
;+
; NAME:
; NORM
;
; PURPOSE:
; 1) This function computes the Euclidean norm of a vector.
; OR
; 2) This function computes the Infinity norm of an array.
;
; CATEGORY:
; Complex Linear Algebra.
;
; CALLING SEQUENCE:
; Result = NORM(A)
;
; INPUTS:
; A: An N-element real or complex vector.
; An M by N real or complex array.
;
; KEYWORD PARAMETERS:
; DOUBLE: If set to a non-zero value, computations are done in
; double precision arithmetic.
;
; EXAMPLE:
; 1) Define an N-element complex vector (a).
; a = [complex(1, 0), complex(2,-2), complex(-3,1)]
; Compute the Euclidean norm of (a).
; result = norm(a)
;
; 2) Define an M by N complex array (a).
; a = [[complex(1, 0), complex(2,-2), complex(-3,1)], $
; [complex(1,-2), complex(2, 2), complex(1, 0)]]
; Compute the Infinity norm of the complex array (a).
; result = norm(a)
;
; PROCEDURE:
; NORM.PRO computes the Euclidean norm of an N-element vector.
; NORM.PRO computes the Infinity norm of an M by N array
;
; REFERENCE:
; ADVANCED ENGINEERING MATHEMATICS (seventh edition)
; Erwin Kreyszig
; ISBN 0-471-55380-8
;
; MODIFICATION HISTORY:
; Written by: GGS, RSI, April 1992
; Modified: GGS, RSI, February 1994
; Computes the Euclidean norm of an N-element vector.
; Accepts complex inputs. Added DOUBLE keyword.
; Modified: GGS, RSI, September 1994
; Added support for double-precision complex inputs.
; Modified: GGS, RSI, April 1996
; Modified keyword checking and use of double precision.
;-
FUNCTION Norm, A, Double = Double
ON_ERROR, 2 ;Return to caller if error occurs.
Type = SIZE(A)
if N_ELEMENTS(Double) eq 0 then $
Double = (Type[Type[0]+1] eq 5) or $
(Type[Type[0]+1] eq 9)
;TOTAL(DoubleData, Double = 0) returns a double-precision result. Cast the
;result to FLOAT if Double = 0.
if Type[0] eq 1 then begin ;If vector, compute the Euclidean norm.
if Double eq 0 then RETURN, $
FLOAT(SQRT(TOTAL(ABS(A)^2, Double = Double))) $ ;ABS needed for complex.
else RETURN, SQRT(TOTAL(ABS(A)^2, Double = Double))
endif else $
if Type[0] eq 2 then begin ;If array, compute the Infinity norm.
if Double eq 0 then RETURN, $
FLOAT(MAX(TOTAL(ABS(A), 1, Double = Double))) $
else RETURN, MAX(TOTAL(ABS(A), 1, Double = Double))
endif else MESSAGE, $
"Input must be an N-element vector or an M by N array."
END